<?php

use common\helpers\Url;
use common\helpers\TimeHelper;
use yii\widgets\LinkPager;
use common\enums\PayTypeEnum;
use common\helpers\Html;
use addons\TinyShop\common\helpers\OrderHelper;
use addons\TinyShop\common\enums\RefundStatusEnum;
use addons\TinyShop\common\enums\AccessTokenGroupEnum;
use common\models\bonus\BonusQi;

$this->title = '本周期奖金';
$this->params['breadcrumbs'][] = $this->title;
$qi = new BonusQi();
?>

<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?= $this->title; ?></h3>
                <div class="box-tools">

                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive">
                <table class="table table-striped table-bordered">
                    <thead>
                    <tr>
                        <th class="text-center">期数</th>
                        <th class="text-center">创建时间</th>
                        <th class="text-center">分享奖</th>
                        <th class="text-center">分布奖</th>
                        <th class="text-center">合作奖</th>
                        <th class="text-center">复消奖</th>
                        <th class="text-center">福利奖</th>
                        <th class="text-center">合计</th>
                        <th class="text-center">扣税</th>
                        <th class="text-center">管理费</th>
                        <th class="text-center">实发</th>
                        <th class="text-center">结算时间</th>
                    </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($list as $k => $model): ?>
                            <tr class="text-center">
                                <td><?=$model['name'];?></td>
                                <?php if(isset($model['model'])):?>
                                    <?php $model = $model['model'];?>
                                    <td>
                                        <?= TimeHelper::timeWeekName($model['created_at']);?> 
                                    </td>
                                    <td><?= $model['bonus_1']?></td>
                                    <td><?= $model['bonus_2']?></td>
                                    <td><?= $model['bonus_3']?></td>
                                    <td><?= $model['bonus_4']?></td>
                                    <td><?= $model['bonus_5']?></td>
                                    <td><?= $model['bonus_7']?></td>
                                    <td><?= $model['tax']?></td>
                                    <td><?= $model['fee']?></td>
                                    <td><?= $model['payment']?></td>
                                    <td>
                                        <?php if($model['status'] == BonusQi::STATUS_DEFAULT):?>
                                            <?php $confirmMsg = $model['id'] % 4 == 0 ? '将结算分布奖、合作奖、复消奖，并释放所有奖金到会员余额。' : '将结算分布奖、合作奖，并释放分享奖、分布奖奖金到会员余额。';?>
                                            <?php if($model['created_at'] < time() - 1860):?>
                                                <?= Html::a('立即结算', Url::to(['calc-qi', 'id'=>$model['id']]), ['class'=>'btn btn-danger', 'onclick'=>'if(!confirm("'.$confirmMsg.'是否确认？"))return false;']);?>
                                                <?php else:?>
                                                    等待结算
                                            <?php endif;?>
                                        <?php else:?>
                                            <?= TimeHelper::timeWeekName($model['end_at']);?> 
                                        <?php endif;?>
                                    </td>
                                <?php else:?>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                <?php endif;?>
                            </tr>
                        <?php endforeach;?>
                    </tbody>
                </table>
                
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
    </div>
</div>
